package coml.allen.api.ack;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * @author sesshomaru
 * @date 2020/11/14 16:23
 */
public class Consumer {

    public static void main(String[] args) throws Exception{
        ConnectionFactory connectionFactory = new ConnectionFactory();

        connectionFactory.setHost("192.168.1.102");
        connectionFactory.setPort(5672);
        connectionFactory.setVirtualHost("/");

        Connection connection = connectionFactory.newConnection();
        Channel channel = connection.createChannel();

        // 开启消息发送确认
        channel.confirmSelect();

        String exchange = "test_ack_ex";
        String routingKey = "ack.#";
        String queueName = "test-ack-queue";

        channel.exchangeDeclare(exchange,"topic",true);
        channel.queueDeclare(queueName,true,false,false,null);
        channel.queueBind(queueName,exchange,routingKey);

        channel.basicConsume(queueName, false ,new MyConsumer(channel));


    }
}
